package testJdk.io.scanner;

import java.util.Scanner;

/**
 * @author keyer
 * @Description : 测试控制台
 * Created by cyd on 2021-04-29 11:54:46
 */
public class ScannerTest {

    public void testOpenAndClose() {
        Scanner input = new Scanner(System.in);

        boolean done = true;
        while (done && input.hasNextLine()) {
            String line = input.nextLine();
            System.out.println("echo: " + line);
            if ("bye".equals(line.trim())) {
                System.out.println("byebye");
                done = false;
            }
        }
        input.close();
    }

    public void testContext() {
        Scanner input = new Scanner(System.in);

        boolean done = true;
        while (done && input.hasNextInt()) {
            Integer line = input.nextInt();
            System.out.println("echo: " + line + "," + line);
            if (line.equals(0)) {
                System.out.println("byebye");
                done = false;
            }
        }
        input.close();
    }

    public static void main(String[] args) {
        ScannerTest test = new ScannerTest();
        test.testContext();

    }
}
